package cn.stylefeng.guns.modular.feedback.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.User.param.UserParam;
import cn.stylefeng.guns.modular.feedback.entity.UserFeedback;
import cn.stylefeng.guns.modular.feedback.param.UserFeedbackParam;
import cn.stylefeng.guns.modular.feedback.service.UserFeedbackService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class UserFeedbackController {

    @Resource
    private UserFeedbackService userFeedbackService;

    @GetMapping("/feedback/list")
    @BusinessLog(title="Feed_waiter增加_查询所有",opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(UserFeedbackParam userFeedbackParam){
        return new SuccessResponseData(userFeedbackService.list(userFeedbackParam));
    }

    @PostMapping("/feedback/add")
    @BusinessLog(title = "user_waiter_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(UserFeedbackParam.add.class) UserFeedbackParam userFeedbackParam){
        userFeedbackService.add(userFeedbackParam);
        userFeedbackService.extractKey(userFeedbackParam.getPid(),userFeedbackParam.getOpinion());
        return new SuccessResponseData();
    }
    @PostMapping("/feedback/delete")
    @BusinessLog(title = "feedbacklist_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(UserFeedbackParam.delete.class) UserFeedbackParam userFeedbackParam) {
        userFeedbackService.delete(userFeedbackParam);
        return new SuccessResponseData();
    }

    @PostMapping("/feedback/edit")
    @BusinessLog(title = "feedbacklist_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(UserFeedbackParam.edit.class) UserFeedbackParam userFeedbackParam) {
        userFeedbackService.edit(userFeedbackParam);
        return new SuccessResponseData();
    }

    @GetMapping("/feedback/top10")
    @BusinessLog(title="查找top10",opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData lookTop10(){
        return new SuccessResponseData(userFeedbackService.lookTopTen());
    }



}
